from appium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import os
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

os.system('adb root')
cap = {
  "platformName": "Android",
  "deviceName": "emulator-5554",
  "noReset": True,
  "appPackage": "com.kongfz.app",
  "appActivity": "com.kongfz.app/com.kongfz.app.home.mvvm.homepage.HomeActivity"
}

driver = webdriver.remote('http://127.0.0.1:4723/wd/hub', cap)

driver.implicitly_wait(25)
sleep(15)

driver.tap([(161, 910)], 500)
sleep(2)
driver.swipe(270, 780, 270, 400, 500)
sleep(2)
driver.swipe(270, 780, 270, 400, 500)

driver.press_keycode(3)

ele = driver.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.FrameLayout[2]/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.LinearLayout/androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[4]/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[2]/android.widget.TextView[1]')
print("定位元素长什么样子", ele)
print("查看元素的属性值：", ele.get_attribute('text'))
ele = driver.find_element(By.XPATH,'//')
driver.find_element_by_android_uiautomator('new UiSelector().text("全部分类")')
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.kongfz.app:id/tv_book_name")')


eles = driver.find_element(By.ID, 'com.kongfz.app:id/tv_book_name')

ele = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, 'com.kongfz.app:id/tv_book_name')))